<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Common_model extends CI_Model{
	private $database;
	function __construct() {  
        parent::__construct();
    	$this->database = $this->load->database("default", true);
	}
	
	/**
	 * @name 显示所有站点信息
     * @param $firstpage 起始条数
     * @param $pagesize 读取条数
     * @return array()
	*/
	function all_clients($firstpage=0, $pagesize=10){
		$result = array();
		$sql = "select * from `test`.dian order by id desc limit ".$firstpage.",".$pagesize;
		$csql = "select * from `test`.dian order by id desc";
        $query = $this->database->query($sql);
        $cquery = $this->database->query($csql);
		$resarr = $query->result_array();
        $count = $cquery->num_rows();
        $result = array("result"=>$resarr, "count"=>$count);
		return $result;
	}
    
    /**
     * @name view_client 根据ID获取站点信息
     * @param $id 站点ID
     * @return array()
    */
    function view_client($id){
        $result = array();
        if($id){
            $sql = "select * from `test`.dian where id=".intval($id);
            $query = $this->database->query($sql);
            $result = $query->row_array();
        }        
        return $result;
    }
	
	/**
	 * 保存站点信息
	*/
	function save_client($list, $where){
		$result = false;
		if($where){
			$result = $this->database->update('dian',$list, $where);
		}else{
            $result = $this->database->insert('dian',$list);
		}
		return $result;
	}
    
    /**
     * @name all_type
     * @param 所有类别
    */
    function all_type(){
        $result = array();
		$sql = "select * from `test`.typeinfo order by id desc";
        $query = $this->database->query($sql);
		$result = $query->result_array();
		return $result;
    }
	
}
